﻿Imports System.Data.SqlClient

Public Class AdminBookLocation
    Inherits System.Web.UI.Page
    Dim p As New Sach_DTO()
    Dim sach As New Sach_BLL()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Try
            load_ke()
            data_sach.DataBind()
        Catch ex As Exception

        End Try

    End Sub
    Public Sub load_ke()
        cb_soke.DataSource = sach.Vitri_Ke()
        cb_soke.DataBind()

    End Sub

    Protected Sub cb_soke_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cb_soke.SelectedIndexChanged
        listbox_hang.Enabled = True
        bt_xoavitri.Disabled = False
    End Sub

    Protected Sub listbox_hang_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles listbox_hang.SelectedIndexChanged
        Try
            p._ke = cb_soke.SelectedItem.Text
            p._hang = listbox_hang.SelectedItem.Value.ToString
            data_sach.DataSource = sach.Load_sachtheovitri(p)
            data_sach.DataBind()
        Catch

        End Try

    End Sub

    Protected Sub data_sach_TailClick(ByVal source As Object, ByVal e As DevExpress.Web.NewsItemEventArgs) Handles data_sach.TailClick

        pc_details.ContentUrl = "~/popup_templates/AdminChangeLocation.aspx?ke=" + cb_soke.SelectedItem.Text + "&hang=" + listbox_hang.SelectedItem.Text + "&idsach=" + e.Item.Name
        pc_details.ShowOnPageLoad = True
        pc_details.HeaderText = "Mã Sách: " + e.Item.Name


    End Sub

    Protected Sub data_sach_DataBinding(ByVal sender As Object, ByVal e As EventArgs) Handles data_sach.DataBinding

        p._ke = cb_soke.SelectedItem.Text
        p._hang = listbox_hang.SelectedItem.Value.ToString
        data_sach.DataSource = sach.Load_sachtheovitri(p)
    End Sub



    Protected Sub bt_xacnhanke_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_xacnhanke.Click
        Try
            p._ke = "K-" + tb_tenke.Text
            sach.ThemKe(p)
            tb_tenke.Text = ""
            successDivKe.Attributes("class") = "alert alert-success"
            successDivKe.Visible = True
            lbl_messke.Text = "Thêm Thành Công!"
            load_ke()
        Catch ex As SqlException
            successDivKe.Attributes("class") = "alert alert-warning"
            successDivKe.Visible = True
            lbl_messke.Text = If(String.IsNullOrEmpty(ex.Message), "Thêm Thất Bại", ex.Message)
        End Try
    End Sub
    Protected Sub bt_xoavitri_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_xoavitri.ServerClick
        Try
            p._ke = cb_soke.SelectedItem.Text
            sach.xoaKe(p)
            successXoaDivKe.Attributes("class") = "alert alert-success"
            successXoaDivKe.Visible = True
            lb_messxoake.Text = "Xóa Thành Công!"
            cb_soke.SelectedIndex = -1
            bt_xoavitri.Disabled = True
            ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "hide_xoake();", True)
            load_ke()
        Catch ex As SqlException
            successXoaDivKe.Attributes("class") = "alert alert-warning"
            successXoaDivKe.Visible = True
            lb_messxoake.Text = If(String.IsNullOrEmpty(ex.Message), "Xóa Thất Bại", ex.Message)
            ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "hide_xoake();", True)
        End Try

    End Sub
End Class